package com.sharedlease.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.sharedlease.entity.R;
import com.sharedlease.entity.Collect_merchant;
import com.sharedlease.service.Collect_merchantService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author 吴钟富
 * @since 2021-03-03
 */
@RestController
@Api(tags = "收藏厂商表相关接口")
@RequestMapping("/collect_merchant")
public class Collect_merchantController {
    @Autowired
    public Collect_merchantService collect_merchantService;

    @GetMapping("/getById/{id}")
    @ApiOperation("根据一个id查询收藏厂商")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "要查询的收藏厂商表的id", defaultValue = "1"),

    }
    )

    public Collect_merchant getByid(@PathVariable Long id) {
        Collect_merchant collect_merchant = collect_merchantService.getById(id);
        return collect_merchant;
    }

    @GetMapping("/getByUid/{uid}")
    @ApiOperation("根据一个uid查询收藏厂商")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "uid", value = "要查询的收藏厂商表的uid", defaultValue = "1"),

    }
    )
    public List<Collect_merchant> getByUid(@PathVariable Long uid) {
        QueryWrapper<Collect_merchant> wrapper = new QueryWrapper<>();
        wrapper.eq("uid", uid);
        List<Collect_merchant> collect_merchants = collect_merchantService.list(wrapper);
        return collect_merchants;
    }

    @GetMapping("/list")
    @ApiOperation("查询全部收藏厂商表记录")
    public List<Collect_merchant> list() {
        List<Collect_merchant> list = collect_merchantService.list(null);
        return list;
    }

    @PostMapping("/save")
    @ApiOperation("新增一个收藏厂商表记录")
    public R save(@RequestBody Collect_merchant collect_merchant) {

        return R.operate(collect_merchantService.save(collect_merchant));
    }

    @PutMapping("/update")
    @ApiOperation("根据id更改一条收藏厂商表记录")
    R update(@RequestBody Collect_merchant collect_merchant) {
        if (collect_merchantService.updateById(collect_merchant)) {
            return R.ok();
        }
        return R.error();
    }

    @DeleteMapping("/removeById/{id}")
    @ApiOperation("根据id删除收藏厂商表记录")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "要删除的收藏厂商id", defaultValue = "-1"),

    }
    )
    R removeById(@PathVariable Long id) {

        return R.operate(collect_merchantService.removeById(id));
    }


}

